/**
 * Copyright (c) 2009 Cerner Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Cerner Corporation - initial API and implementation
 */
package com.cerner.system.rest.jaas.cas.functional;

import java.util.HashMap;
import java.util.Map;

import javax.security.auth.login.AppConfigurationEntry;
import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;

import com.cerner.system.rest.jaas.cas.CasLoginModule;

/**
 * Simple {@link javax.security.auth.login.Configuration} that enables CAS for
 * JAAS.
 * 
 * @author Alex Horn
 */
class CasJaasConfiguration extends javax.security.auth.login.Configuration {

  /**
   * Property name for {@code casLoginUrl} for CAS-specific
   * {@link javax.security.auth.spi.LoginModule} option.
   */
  static String CAS_LOGIN_URL_OPTION = "casLoginUrl";

  /**
   * Lexical representation of the CAS URL passed to JAAS.
   */
  final String casLoginUrl;

  CasJaasConfiguration(String casLoginUrl) {
    this.casLoginUrl = casLoginUrl;
  }

  @Override
  public AppConfigurationEntry[] getAppConfigurationEntry(String name) {

    final Map<String, String> casSettings = new HashMap<String, String>();
    casSettings.put(CAS_LOGIN_URL_OPTION, this.casLoginUrl);

    return new AppConfigurationEntry[] { new AppConfigurationEntry(
        CasLoginModule.class.getName(), LoginModuleControlFlag.REQUIRED,
        casSettings) };
  }

  @Override
  public void refresh() {
    return;
  }

}
